package tgc.edu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.tms.custom.BaseEntity;

@Entity
public class Curriculum extends BaseEntity<Integer> {
	private String kcmc; // 课程名称
	private String kcdm; // 课程代码
	private Integer zongxs; // 总学时
	private float xf; // 学分
	private Integer jsxs; // 讲授学时
	private Integer syxs; // 实验学时
	private Integer sjxs; // 上机学时
	private Integer qtxs; // 其他学时
	private List<CourseCategory> kclbs = new ArrayList<>(); // 课程类别
	private Integer zhouxs; // 每周学时
	private String khfs; // 考核方式
	private String kkxq; // 开课学期
	private Profession profession; // 选择专业表
	
	@JsonIgnore
	private List<EducationalPlanner> ep = new ArrayList<>();

	public Integer getSjxs() {
		return sjxs;
	}

	public void setSjxs(Integer sjxs) {
		this.sjxs = sjxs;
	}

	@ManyToMany(cascade=CascadeType.PERSIST)
	@JoinTable(name = "tb_curriculum_kclb", joinColumns = @JoinColumn(name = "curriculum_id"), inverseJoinColumns = @JoinColumn(name = "kclb_id"))
	public List<CourseCategory> getKclbs() {
		return kclbs;
	}

	public void setKclbs(List<CourseCategory> kclbs) {
		this.kclbs = kclbs;
	}

	@ManyToOne(cascade = CascadeType.PERSIST)
	public Profession getProfession() {
		return profession;
	}

	public void setProfession(Profession profession) {
		this.profession = profession;
	}

	private String bz; // 备注

	public String getKcmc() {
		return kcmc;
	}

	public void setKcmc(String kcmc) {
		this.kcmc = kcmc;
	}

	public String getKcdm() {
		return kcdm;
	}

	public void setKcdm(String kcdm) {
		this.kcdm = kcdm;
	}

	public Integer getZongxs() {
		return zongxs;
	}

	public void setZongxs(Integer zongxs) {
		this.zongxs = zongxs;
	}

	public float getXf() {
		return xf;
	}

	public void setXf(float xf) {
		this.xf = xf;
	}

	public Integer getJsxs() {
		return jsxs;
	}

	public void setJsxs(Integer jsxs) {
		this.jsxs = jsxs;
	}

	public Integer getSyxs() {
		return syxs;
	}

	public void setSyxs(Integer syxs) {
		this.syxs = syxs;
	}

	public Integer getQtxs() {
		return qtxs;
	}

	public void setQtxs(Integer qtxs) {
		this.qtxs = qtxs;
	}

	public Integer getZhouxs() {
		return zhouxs;
	}

	public void setZhouxs(Integer zhouxs) {
		this.zhouxs = zhouxs;
	}

	public String getKhfs() {
		return khfs;
	}

	public void setKhfs(String khfs) {
		this.khfs = khfs;
	}

	public String getKkxq() {
		return kkxq;
	}

	public void setKkxq(String kkxq) {
		this.kkxq = kkxq;
	}

	public String getBz() {
		return bz;
	}

	public void setBz(String bz) {
		this.bz = bz;
	}

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "curriculum")
	public List<EducationalPlanner> getEp() {
		return ep;
	}

	public void setEp(List<EducationalPlanner> ep) {
		this.ep = ep;
	}

	/**
	 * 前台获取年级
	 * 
	 * @return
	 */
	@Transient
	public String getYear() {
		return profession == null ? null : profession.getYear();
	}

	/**
	 * 前台获取学院
	 * 
	 * @return
	 */
	@Transient
	public String getCollege() {
		return profession == null ? null : profession.getCollege();
	}

	/**
	 * 前台获取专业
	 * 
	 * @return
	 */
	@Transient
	public String getProfesion() {
		return profession == null ? null : profession.getProfesion();
	}

	/**
	 * 前台获取课程类别
	 * 
	 * @return
	 */
	@Transient
	public String getKclb() {
		if(kclbs.size()>0) {
			String str = "";
			for (CourseCategory c : kclbs) {
				str += c.getType() + "/";
			}
			return str.substring(0, str.length() - 1);
		}else {
			return "";
		}
		
	}

	/**
	 * 获取类别id列表
	 * 
	 * @return
	 */
	@Transient
	public List<Integer> getLbs() {
		List<Integer> list = new ArrayList<>();
		for (CourseCategory c : kclbs) {
			list.add(c.getId());
		}
		return list;
	}

}
